# This mkfile expects the following directory structure:
# 64/        - directory with 64-bit ASL library (amplsolver.a)
# solvers/   - ASL solvers directory
#   b/       - output directory
#   include/ - C++ API headers
#   src/     - C++ API and localsolver source
#   mkfile   - this mkfile

BUILTINS =
NPROC = 1
LIBFORMAT = static_pic

LDIR  = /usr/local/locsol/5_0
LOCALSOLVER_INC = $LDIR/include

S = ../32
S64 = ../64
ALIB = amplsolver.a
#LIBS = -lnsl -lm -ldl -lpthread
L32 = /usr/local/olib32
LIBS = $L32/libnsl.so.1 $L32/libdl.so.2 $L32/libpthread.so.0 $L32/libstdc++.so.6 $L32/libm.so.6 $L32/libgcc_s.so.1 $L32/libc.so.6 $L32/ld-linux.so.2

g = -O2
gs = -std=c++11 -DHAVE_UNORDERED_MAP
CXX = g++ -m32
CXX64 = g++
CC = cc -m32
CC64 = cc
CXX11_FLAGS = -std=c++11 -DMP_USE_UNORDERED_MAP -DMP_NO_CLOCK_GETTIME

CFLAGS = -I$LOCALSOLVER_INC -Iinclude -Isrc -I. $CXX11_FLAGS -DMP_NOMAIN
Rpath32 = -Wl,-rpath,.,-rpath,/usr/local/lib
Rpath64 = -Wl,-rpath,.,-rpath,/usr/local/lib64
L = $Rpath32 -lstdc++ -L $LDIR/linux32 -llocalsolver $LDMTFLAGS $S/$ALIB $LIBS
Lg = $Rpath32 -lstdc++ -L $LDIR/linux32 -llocalsolver $LDMTFLAGS $S/asg.a $LIBS
L640 = $S64/olib
Lb64 = $L640/libnsl.so.1 $L640/libdl.so.2 $L640/libpthread.so.0 $L640/libstdc++.so.6 $L640/libm.so.6 $L640/libgcc_s.so.1 $L640/libc.so.6 $L640/ld-linux-x86-64.so.2

L64 = $Rpath64 -L $LDIR/linux64 -llocalsolver $LDMTFLAGS $S64/$ALIB -lnsl -ldl -lpthread -lm

all:V: b/locsol32 b/locsol64 b/locsol32lt b/locsol64lt

util = \
	src/asl/aslbuilder.cc \
	src/asl/aslexpr.cc \
	src/asl/aslproblem.cc \
	src/asl/aslsolver.cc \
	src/clock.cc \
	src/expr-info.cc \
	src/format.cc \
	src/nl.cc \
	src/option.cc \
	src/os.cc \
	src/posix.cc \
	src/rstparser.cc \
	src/sol.cc \
	src/solver.cc \
	src/localsolver/main.cc

b/util32.a: $util
	$CXX -c $g -I$S $CFLAGS $newprereq
	o=`echo $newprereq|sed 's![^ ]*/!!g;s!asl/!!g;s/\.cc/.o/g'`
	echo $o
	ar ruv $target $o
	rm $o
	ranlib $target

b/util32g.a: $util
	$CXX -c -g -I$S $CFLAGS $newprereq
	o=`echo $newprereq|sed 's![^ ]*/!!g;s!asl/!!g;s/\.cc/.o/g'`
	ar ruv $target $o
	rm $o
	ranlib $target

b/util64.a: $util
	$CXX64 -c $g -I$S64 $CFLAGS $newprereq
	o=`echo $newprereq|sed 's![^ ]*/!!g;s!asl/!!g;s/\.cc/.o/g'`
	ar ruv $target $o
	rm $o
	ranlib $target

locsol_date.h: $util src/localsolver/localsolver.cc src/solver.cc locsolmain.c licmain1.c
	now=`Dt -8 $prereq`
	echo -e "#define YYYYMMDD $now\n#define qYYYYMMDD "'"'"$now"'"'"\n#define lYYYYMMDD $now" >$target

b/%_32.o: src/%.cc locsol_date.h
	$CXX -c -o $target -I$S $CFLAGS $prereq

b/%_64.o: src/%.cc locsol_date.h
	$CXX64 -c -o $target -I$S64 $CFLAGS $prereq

b/locsol32: src/localsolver/localsolver.cc b/util32.a locsol_date.h
	$CC -c $g -I. -I$S locsolmain.c
	$CXX -s -o $target -I$S $CFLAGS locsolmain.o $prereq $L
	rm locsolmain.o

b/locsol32lt: src/localsolver/localsolver.cc b/util32.a locsol_date.h
	$CC -c $g -I. -I$S -DTime_Limited locsolmain.c
	$CXX -s -o $target -I$S $CFLAGS locsolmain.o $prereq $L
	rm locsolmain.o

b/locsol32ltg: src/localsolver/localsolver.cc b/util32g.a locsol_date.h
	$CC -c -g -I. -I$S -DTime_Limited locsolmain.c
	$CXX -g -o $target -I$S $CFLAGS locsolmain.o $prereq $Lg
	rm locsolmain.o

b/locsol32g: src/localsolver/localsolver.cc b/util32g.a locsol_date.h
	$CC -c -g -I$S locsolmain.c
	$CXX -g -o $target -I$S $CFLAGS locsolmain.o $prereq $Lg
	rm locsolmain.o

b/locsol64: src/localsolver/localsolver.cc b/util64.a locsol_date.h
	$CC64 -c $g -I. -I$S64 locsolmain.c
	$CXX64 -s -o $target -I$S64 $CFLAGS locsolmain.o $prereq $L64
	rm locsolmain.o

b/locsol64lt: src/localsolver/localsolver.cc b/util64.a locsol_date.h
	$CC64 -c $g -I. -I$S64 -DTime_Limited locsolmain.c
	$CXX64 -s -o $target -I$S64 $CFLAGS locsolmain.o $prereq $L64
	rm locsolmain.o
